package me.firstapp.manage.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.manage.common.BaseManage;
import me.firstapp.module.weixin.jinbi.JinBiAccount;
import me.firstapp.module.weixin.member.Member;
import me.firstapp.module.weixin.member.SoftFee;
import me.firstapp.module.weixin.weibi.WeiBiAccount;
import me.firstapp.service.weixin.account.JinBiAccountService;
import me.firstapp.service.weixin.account.WeiBiAccountService;
import me.firstapp.service.weixin.member.MemberService;
import me.firstapp.service.weixin.soft.SoftFeeService;

@Controller
@RequestMapping(value = "/memberManage")
public class MemberManagePage extends BaseManage {

	@Autowired
	private SoftFeeService softFeeService;

	@Autowired
	private MemberService memberService;

	@Autowired
	private WeiBiAccountService weiBiAccountService;

	@Autowired
	private JinBiAccountService jinBiAccountService;

	@RequestMapping(value = "/cardFeeList.html", method = RequestMethod.GET)
	public ModelAndView cardFeeListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("member/cardFeeList", modelMap);
	}

	@RequestMapping(value = "/cardFeeAdd.html", method = RequestMethod.GET)
	public ModelAndView cardFeeAddView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("member/cardFeeAdd", modelMap);
	}

	@RequestMapping(value = "/cardFeeUpdate.html", method = RequestMethod.GET)
	public ModelAndView cardFeeUpdateView(Long id, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		SoftFee cardFee = softFeeService.findSoftFee(id);
		modelMap.put("cardFee", cardFee);
		modelMap.put("defLevel", cardFee.getVipLevel());
		modelMap.put("defLevelName", Member.levelMap.get(cardFee.getVipLevel()));
		modelMap.put("cardFeeId", cardFee.getId());
		return new ModelAndView("member/cardFeeUpdate", modelMap);
	}

	@RequestMapping(value = "/memberList.html", method = RequestMethod.GET)
	public ModelAndView memberListView(Integer vipLevel, String partnerOpenId, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		modelMap.put("vipLevel", vipLevel);
		modelMap.put("partnerOpenId", partnerOpenId);
		return new ModelAndView("member/memberList", modelMap);
	}

	@RequestMapping(value = "/editMember.html", method = RequestMethod.GET)
	public ModelAndView editMemberView(String openId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		Member member = memberService.findMemberByOpenId(openId);
		modelMap.put("member", member);
		modelMap.put("status", member.getStatus());
		if (Member.STATUS_USE == member.getStatus()) {
			modelMap.put("statusStr", "启用");
		} else if (Member.STATUS_NO_USE == member.getStatus()) {
			modelMap.put("statusStr", "停用");
		}
		modelMap.put("followStatus", member.getFollowStatus());
		if (Member.FOLLOW_STATUS_YES == member.getFollowStatus()) {
			modelMap.put("followStatusStr", "已关注");
		} else if (Member.FOLLOW_STATUS_NO == member.getFollowStatus()) {
			modelMap.put("followStatusStr", "未关注");
		}
		modelMap.put("openId", member.getOpenId());
		return new ModelAndView("member/editMember", modelMap);
	}

	@RequestMapping(value = "/weibiTraceList.html", method = RequestMethod.GET)
	public ModelAndView weibiTraceListView(String openId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		Member member = memberService.findMemberByOpenId(openId);
		modelMap.put("member", member);
		modelMap.put("openId", member.getOpenId());
		WeiBiAccount weiBiAccount = weiBiAccountService.findWeiBiAccountByCardNoAndOpenId(member.getCardNo(), openId);
		modelMap.put("weiBiAccount", weiBiAccount);
		return new ModelAndView("member/weibiTraceList", modelMap);
	}

	@RequestMapping(value = "/weibiTz.html", method = RequestMethod.GET)
	public ModelAndView weibiTzView(Long weiBiAccountId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("weiBiAccountId", weiBiAccountId);
		return new ModelAndView("member/weibitz", modelMap);
	}

	@RequestMapping(value = "/jinbiTraceList.html", method = RequestMethod.GET)
	public ModelAndView jinbiTraceListView(String openId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		Member member = memberService.findMemberByOpenId(openId);
		modelMap.put("member", member);
		modelMap.put("openId", member.getOpenId());
		JinBiAccount jinBiAccount = jinBiAccountService.findJinBiAccountByCardNoAndOpenId(member.getCardNo(), openId);
		modelMap.put("jinBiAccount", jinBiAccount);
		return new ModelAndView("member/jinbiTraceList", modelMap);
	}

	@RequestMapping(value = "/jinbiTz.html", method = RequestMethod.GET)
	public ModelAndView jinbiTzView(Long jinBiAccountId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("jinBiAccountId", jinBiAccountId);
		return new ModelAndView("member/jinbitz", modelMap);
	}

	@RequestMapping(value = "/partnerList.html", method = RequestMethod.GET)
	public ModelAndView partnerListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("member/partnerList", modelMap);
	}

	@RequestMapping(value = "/addPartnerAgents.html", method = RequestMethod.GET)
	public ModelAndView addPartnerAgentsView(String openId, HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		modelMap.put("openId", openId);
		return new ModelAndView("member/addPartnerAgents", modelMap);
	}

	@RequestMapping(value = "/spreadOrderList.html", method = RequestMethod.GET)
	public ModelAndView spreadOrderListView(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		return new ModelAndView("member/spreadOrderList", modelMap);
	}
}
